package com.yyds.controller;

import com.yyds.common.MyJSON;
import com.yyds.common.R;
import com.yyds.service.PersonVolunteerService;
import com.yyds.vo.EchartBarVo;
import com.yyds.vo.PersonVolunteerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author 花君瑜
 * @date 2022/10/14 08:30:40
 * @desc 志愿者信息管理模块
 **/
@RestController
@RequestMapping("/admin/person/volunteer")
public class PersonVolunteerController {
    @Autowired
    private PersonVolunteerService personVolunteerService;

    //查询全部志愿者信息
    @RequestMapping("/queryAllVolunteer")
    public MyJSON<PersonVolunteerVo> queryAllPersonVolunteerController(@RequestParam Map<String, Object> params) {
        // 注意 这里使用 map来接受参数  前端传的不定参数 都可以封装到 map 中
        System.out.println("public MyJSON<PersonVolunteer> queryAllPersonVolunteerController(@RequestParam Map<String, Object> params) ="+params);
        return personVolunteerService.queryAllPersonVolunteerService(params);
    }

    //根据id删除志愿者信息
    @PostMapping("/deleteVolunteer")
    public R deletePersonVolunteerController(Integer volunteer_id) {
        System.out.println("public R deletePersonVolunteerController(Integer Volunteer_id) = "+volunteer_id);
        int result = personVolunteerService.deletePersonVolunteerService(volunteer_id);
        return result > 0 ? R.ok() : R.error();
    }

    //删除部分志愿者信息
    @RequestMapping("/deleteAllVolunteer")
    public R deleteAllPersonVolunteerController(String str) {
        System.out.println("public R deleteAllPersonVolunteerController(String str)" + str);
        Integer i = personVolunteerService.deleteAllPersonVolunteerService(str);
        return i > 0 ? R.ok() : R.error();
    }

    //添加志愿者
    @RequestMapping("/addVolunteer")
    public R addPersonVolunteerController(PersonVolunteerVo personVolunteerVo){
        int result = personVolunteerService.addPersonVolunteerService(personVolunteerVo);
        return result > 0 ? R.ok() : R.error();
    }

    //修改志愿者
    @RequestMapping("/updateVolunteer")
    public R updatePersonVolunteerController(PersonVolunteerVo personVolunteerVo,Integer volunteer_id){
        System.out.println("public R updatePersonVolunteerController(PersonVolunteerVo personVolunteerVo) = "+personVolunteerVo);
        System.out.println(volunteer_id);
        int result = personVolunteerService.updatePersonVolunteerService(personVolunteerVo,volunteer_id);
        return result > 0 ? R.ok() : R.error();
    }

    //查询所有地区名称
    @RequestMapping("/queryRegionName")
    public R queryAllRegionNameController() {
        List<String> list = personVolunteerService.queryAllRegionNameService();
        return R.ok().data("regionName", list);
    }

    //生成地区柱状图
    @RequestMapping("/queryPersonVolunteerEchartBar")
    public R queryPersonVolunteerController(){
        //将从数据库读取的 地区名称 数量 放到集合中发送到前端
        List<EchartBarVo> list = personVolunteerService.queryPersonVolunteerService();
        return R.ok().data("areaBar",list);
    }
}
